/*******************************************************************************
 * $Header: /cvsroot/oloa/org.gocom.bpm.platform.model/src/org/gocom/bpm/platform/model/web/taglib/ScriptGenerator.java,v 1.1 2011/07/03 02:30:16 hufulai Exp $
 * $Revision: 1.1 $
 * $Date: 2011/07/03 02:30:16 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved.
 * 
 * Created on 2010-5-26
 *******************************************************************************/

package com.atozsoft.wf.taglib;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.primeton.workflow.commons.config.WFConfigurationHelper;
import com.primeton.workflow.commons.utility.StringUtil;
import com.primeton.workflow.model.definition.WFNote;

/**
 * 
 * ��չ���Զ���ͼƬ.Ĭ��ͼƬ�ļ������<BR>
 * workflow\wfcomponent\web\images\processInst_graph\���̶���ID\�����ID_�״̬.gif<BR>
 * workflow\wfcomponent\web\images\processDef_graph\���̶���ID\�����ID_�״̬.gif<BR>
 *
 * @author wengzr (mailto:wengzr@primeton.com)
 */
/*
 * Modify history
 * $Log: ScriptGenerator.java,v $
 * Revision 1.1  2011/07/03 02:30:16  hufulai
 * �?���ÿ��
 *
 * Revision 1.1  2011/04/06 02:07:09  supyuser
 * *** empty log message ***
 *
 */
public class ScriptGenerator
{
    private int m_left;
    private int m_top;
    private int m_lineWidth;
    public String m_unStartColor;
    public String m_startColor;
    public String m_finishColor;
    public double m_zoomQuotiety;
    
    private String imagePath;
    
    //Ӧ��·��
    private String webAppPath;
    
    //���̶�����
    private String processDefName;
    
    private int imageSize;
    private int hypotenuseSize;
    private double angle;
    private byte fontSize;
    private String contextPath;

    public ScriptGenerator(int aLeft, int aTop, int aLineWidth, double zoomQuotiety, String contextPath)
    {
        m_left = 0;
        m_top = 0;
        m_lineWidth = 1;
        m_unStartColor = "#BCBCBC";
        m_startColor = "#A52A2A";
        m_finishColor = "#228B22";
        m_zoomQuotiety = 1.0D;
        imagePath = "";
        imageSize = 40;
        hypotenuseSize = 10;
        angle = 20D;
        fontSize = 10;
        m_lineWidth = aLineWidth;
        m_left = aLeft;
        m_top = aTop;
        m_zoomQuotiety = zoomQuotiety;
        this.contextPath=contextPath;
        imagePath = (new StringBuilder()).append(contextPath).append("/").append(WFConfigurationHelper.retrieveWFConfiguration().getProcessGraphImagePath()).toString();
    }

    public void handleState(StringBuffer buf, State s)
    {
        drawImage(buf, s.getID(), getStateImgUrl(s), s.getX() + m_left, s.getY() + m_top, s.getMouseEvents(), s.getExtendAttribute());
        drawText(buf, s.getName(), fontSize, getStateTextPosition(s).x, getStateTextPosition(s).y, StringUtil.ifNullToBlank(s.getName()).length() * 2 * 10, imageSize);
    }
    
    public void handleNote(StringBuffer buf,WFNote note){
    	//----Modify begin----Huangheliang 2012.03.23
    	//drawNote(buf, note.getTitle(), fontSize, Integer.parseInt(note.getLocation_x()), Integer.parseInt(note.getLocation_y()), Integer.parseInt(note.getWidth()), Integer.parseInt(note.getHeight()));
    	drawNote(buf, note.getTitle(), fontSize, (int)Math.round(Double.parseDouble(note.getLocation_x())), (int)Math.round(Double.parseDouble(note.getLocation_y())), (int)Math.round(Double.parseDouble(note.getWidth())), (int)Math.round(Double.parseDouble(note.getHeight())));
    	//----Modify End----
    }
    
    public void handleHeader(StringBuffer buf,String processName,String processInstName){
    	drawHeader(buf, processName, processInstName, fontSize, 0, 0, 400, 50);
    }

    private void handleConnector(StringBuffer bufLine, StringBuffer bufLineText, ConnectionImpl c)
    {
        String strFrom = null;
        String strTo = null;
        StateImpl sFrom = c.getFromState();
        StateImpl sTo = c.getToState();
        String StateColor = m_unStartColor;
        int sumX = 0;
        int sumY = 0;
        HashMap hm = c.getHm();
        boolean isDrawed = false;
        boolean computedTextPosition = false;
        if(c.getType() == 0)
            StateColor = m_unStartColor;
        else
        if(c.getType() == 2)
            StateColor = m_startColor;
        else
        if(c.getType() == 1)
            StateColor = m_finishColor;
        if(sFrom != null)
            strFrom = sFrom.getName();
        if(sTo != null)
            strTo = sTo.getName();
        Point curBegin = new Point(m_left, m_top);
        Point curEnd = new Point(m_left, m_top);
        if(sFrom != null && sTo != null)
        {
            curBegin.x = m_left + sFrom.getX() + imageSize / 2;
            curBegin.y = m_top + sFrom.getY() + imageSize / 2;
            curEnd.x = m_left + sTo.getX() + imageSize / 2;
            curEnd.y = m_top + sTo.getY() + imageSize / 2;
        }
        drawScriptComment(bufLine, (new StringBuilder()).append("From:").append(strFrom).append(";To:").append(strTo).toString());
        if(hm.isEmpty() && sFrom != null && sTo != null)
        {
            bufLine.append((new StringBuilder()).append("color=\"").append(StateColor).toString());
            bufLine.append("\"\r\n");
            curBegin = decreaseBegin(curBegin, curEnd, imageSize / 2);
            curEnd = decrease(curBegin, curEnd, imageSize / 2);
            drawArrowLine(bufLine, curBegin, curEnd, angle);
            isDrawed = true;
            sumX = (curBegin.x + curEnd.x) / 2;
            sumY = (curBegin.y + curEnd.y) / 2;
        }
        if(hm != null && !isDrawed && sFrom != null && sTo != null)
        {
            Point curBegin2 = new Point(m_left, m_top);
            Point curEnd2 = new Point(m_left, m_top);
            curBegin2 = (Point)curBegin.clone();
            int j = 1;
            boolean isdecreaseBegin = false;
            int remainder = hm.size() % 8;
            int i = 0;
            do
            {
                if(i >= hm.size())
                    break;
                int relativeX1 = Integer.parseInt((String)hm.get((new StringBuilder()).append(j).append("w1").toString()));
                int relativeY1 = Integer.parseInt((String)hm.get((new StringBuilder()).append(j).append("h1").toString()));
                curEnd2.x = curBegin.x + relativeX1;
                curEnd2.y = curBegin.y + relativeY1;
                if(!computedTextPosition)
                    if(remainder == 0)
                    {
                        if(i == hm.size() / 2)
                        {
                            sumX = (curBegin2.x + curEnd2.x) / 2;
                            sumY = (curBegin2.y + curEnd2.y) / 2;
                            computedTextPosition = true;
                        }
                    } else
                    if(i == (hm.size() + 4) / 2)
                    {
                        sumX = curBegin2.x;
                        sumY = curBegin2.y;
                        computedTextPosition = true;
                    } else
                    if(hm.size() == 4)
                    {
                        sumX = curEnd2.x;
                        sumY = curEnd2.y;
                        computedTextPosition = true;
                    }
                if(!isdecreaseBegin)
                {
                    curBegin2 = decreaseBegin(curBegin2, curEnd2, imageSize / 2);
                    isdecreaseBegin = true;
                }
                bufLine.append((new StringBuilder()).append("color=\"").append(StateColor).toString());
                bufLine.append("\"\r\n");
                drawLine(bufLine, curBegin2, curEnd2, 0, false);
                j++;
                i += 4;
                curBegin2 = (Point)curEnd2.clone();
                if(i == hm.size())
                {
                    curEnd = decrease(curEnd2, curEnd, imageSize / 2);
                    drawArrowLine(bufLine, curEnd2, curEnd, angle);
                }
            } while(true);
        }
        if(c.getDescription().length() > 1)
            drawText(bufLineText, c.getDescription(), fontSize, sumX - c.getDescription().length() * 10, sumY, c.getDescription().length() * 2 * 10, imageSize);
    }

    private void drawText(StringBuffer buf, String val, int fontSize, int left, int top, int width, int height)
    {
        buf.append("<input type=\"text\" readonly style=\"background:transparent;position:absolute;border:0;");
        buf.append((new StringBuilder()).append("font-size:").append(Math.round(9D * m_zoomQuotiety)).append("pt;").toString());
        buf.append((new StringBuilder()).append("left:").append(Math.round((double)left * m_zoomQuotiety)).append(";top:").append(Math.round((double)top * m_zoomQuotiety)).toString());
        buf.append((new StringBuilder()).append(";width:").append(Math.round((double)width * m_zoomQuotiety)).append(";height:").append(Math.round((double)height * m_zoomQuotiety)).toString());
        buf.append(";text-align:center");
        buf.append((new StringBuilder()).append("\" value=\"").append(val).append("\">\r\n").toString());
    }

    private void drawNote(StringBuffer buf, String val, int fontSize, int left, int top, int width, int height)
    {
    	
    	String id="";
    	if(width<50)
    		id="ordinateDiv"; //�����
    	else
    		id="reclineDiv";//�����
    	
    	String topStyle="dotted";
    	//û�б���ʱ��������������ʾ
    	if(val==null||"".equals(val))
    		topStyle="none";
    	
    	
        buf.append("<div id='"+id+"' onmouseenter=\"this.style.backgroundColor='EEFFDD';\" onmouseleave=\"this.style.backgroundColor='white'\" style=\"background:transparent;position:absolute;border:1px solid;border-top-width: thin;border-right-width: solid;border-bottom-width: solid;border-left-width: solid;border-top-style: "+topStyle+";border-right-style: dotted;border-bottom-style: dotted;border-left-style: dotted;border-top-color: #00CC66;border-right-color: #0099CC;border-bottom-color: #FF0000;border-left-color: #6699FF;");
        buf.append((new StringBuilder()).append("font-size:").append(Math.round(9D * m_zoomQuotiety)).append("pt;").toString());
        buf.append((new StringBuilder()).append("left:").append(Math.round((double)left * m_zoomQuotiety)).append(";top:").append(Math.round((double)top * m_zoomQuotiety)).toString());
        buf.append((new StringBuilder()).append(";width:").append(Math.round((double)width * m_zoomQuotiety)).append(";height:").append(Math.round((double)height * m_zoomQuotiety)).toString());
        buf.append(";text-align:center");
        buf.append("\">\r\n");
        buf.append("<span style=\"display:block;background:EEFFDD;\" >");
        buf.append(val);
        buf.append("</span>");

        buf.append("</div>\r\n");
        //buf.append((new StringBuilder()).append("\" value=\"").append(val).append("\">\r\n").toString());
    }
    
    
    private void drawHeader(StringBuffer buf, String processName,String processInstName, int fontSize, int left, int top, int width, int height)
    {
        buf.append("<div id='processHeader' style=\"background:transparent;position:absolute;border:1px solid;border-top-width: thin;border-right-width: solid;border-bottom-width: solid;border-left-width: solid;border-top-style: dotted;border-right-style: dotted;border-bottom-style: dotted;border-left-style: dotted;border-top-color: #00CC66;border-right-color: #0099CC;border-bottom-color: #FF0000;border-left-color: #6699FF;");
        buf.append((new StringBuilder()).append("font-size:").append(Math.round(9D * m_zoomQuotiety)).append("pt;").toString());
        buf.append((new StringBuilder()).append("left:").append(Math.round((double)left * m_zoomQuotiety)).append(";top:").append(Math.round((double)top * m_zoomQuotiety)).toString());
        buf.append((new StringBuilder()).append(";width:").append(Math.round((double)width * m_zoomQuotiety)).append(";height:").append(Math.round((double)height * m_zoomQuotiety)).toString());
        buf.append(";text-align:left");
        buf.append("\">\r\n");
        buf.append("<span style=\"display:block;background:EEFFDD;\">");
        buf.append("<li>").append(processName).append("</li>");
        if(processInstName!=null){
        	buf.append("<li>").append(processInstName).append("</li>");
        }
        buf.append("</span>");
        
        buf.append("</div>");
    }
    
    private void drawImage(StringBuffer buf, String id, String src, int left, int top, Object eventHandles, Map extendAttributes)
    {
        buf.append("<IMG ");
        buf.append((new StringBuilder()).append("id=\"").append(id).append("\" ").toString());
        buf.append((new StringBuilder()).append("SRC=\"").append(src).append("\" ").toString());
        buf.append((new StringBuilder()).append(StringUtil.ifNullToBlank(eventHandles)).append(" ").toString());
        buf.append("style=\"position:absolute;border:0;");
        buf.append((new StringBuilder()).append("left:").append((double)left * m_zoomQuotiety).append(";top:").append((double)top * m_zoomQuotiety).toString());
        buf.append((new StringBuilder()).append(";width:").append((double)imageSize * m_zoomQuotiety).append(";height:").append((double)imageSize * m_zoomQuotiety).toString());
        buf.append(";cursor:hand\"");
        if(extendAttributes != null)
        {
            StringBuffer extAttr = new StringBuffer();
            for(Iterator keys = extendAttributes.keySet().iterator(); keys.hasNext(); extAttr.append("\""))
            {
                Object key = keys.next();
                Object value = extendAttributes.get(key);
                extAttr.append(" ");
                extAttr.append(key);
                extAttr.append("=");
                extAttr.append("\"");
                extAttr.append(value);
            }

            buf.append(extAttr);
        }
        buf.append(">\r\n");
    }

    private void drawLine(StringBuffer buf, Point ptBegin, Point ptEnd, int ignore, boolean isArrow)
    {
        if((double)Math.abs(ptEnd.x - ptBegin.x) < (double)ignore * m_zoomQuotiety)
            ptEnd.x = ptBegin.x;
        if((double)Math.abs(ptEnd.y - ptBegin.y) < (double)ignore * m_zoomQuotiety)
            ptEnd.y = ptBegin.y;
        if(isArrow)
            buf.append("lineWidth=1\r\n");
        else
            buf.append((new StringBuilder()).append("lineWidth=").append(m_lineWidth).append("\r\n").toString());
        buf.append((new StringBuilder()).append("Line(").append(Math.round((double)ptBegin.x * m_zoomQuotiety)).append(",").append(Math.round((double)ptBegin.y * m_zoomQuotiety)).append(",").toString());
        buf.append((new StringBuilder()).append(Math.round((double)ptEnd.x * m_zoomQuotiety)).append(",").append(Math.round((double)ptEnd.y * m_zoomQuotiety)).append(");\r\n").toString());
        buf.append("Ox = -1;Oy = -1;\r\n");
    }

    private void drawScriptComment(StringBuffer buf, String strComment)
    {
        buf.append("/*");
        buf.append(strComment);
        buf.append("*/");
        buf.append("\r\n");
    }

    private Point decrease(Point ptBegin, Point ptEnd, int len)
    {
        int dx = ptEnd.x - ptBegin.x;
        int dy = ptEnd.y - ptBegin.y;
        boolean xIsLarge = false;
        boolean yIsLarge = false;
        if(dx < 0)
            xIsLarge = true;
        if(dy < 0)
            yIsLarge = true;
        if(dx == 0 && dy == 0)
            return ptEnd;
        if(dx == 0)
            if(yIsLarge)
                return new Point(ptEnd.x, ptEnd.y + len);
            else
                return new Point(ptEnd.x, ptEnd.y - len);
        if(dy == 0)
            if(xIsLarge)
                return new Point(ptEnd.x + len, ptEnd.y);
            else
                return new Point(ptEnd.x - len, ptEnd.y);
        dx = Math.abs(dx);
        dy = Math.abs(dy);
        int decline = (int)Math.sqrt(Math.pow(dx, 2D) + Math.pow(dy, 2D));
        int _x = (len * dx) / decline;
        int _y = (len * dy) / decline;
        if(xIsLarge && yIsLarge)
            return new Point(ptEnd.x + _x, ptEnd.y + _y);
        if(xIsLarge)
            return new Point(ptEnd.x + _x, ptEnd.y - _y);
        if(yIsLarge)
            return new Point(ptEnd.x - _x, ptEnd.y + _y);
        else
            return new Point(ptEnd.x - _x, ptEnd.y - _y);
    }

    private Point decreaseBegin(Point ptBegin, Point ptEnd, int len)
    {
        int dx = ptEnd.x - ptBegin.x;
        int dy = ptEnd.y - ptBegin.y;
        boolean xIsLarge = false;
        boolean yIsLarge = false;
        if(dx < 0)
            xIsLarge = true;
        if(dy < 0)
            yIsLarge = true;
        if(dx == 0 && dy == 0)
            return ptBegin;
        if(dx == 0)
            if(yIsLarge)
                return new Point(ptBegin.x, ptBegin.y - len);
            else
                return new Point(ptBegin.x, ptBegin.y + len);
        if(dy == 0)
            if(xIsLarge)
                return new Point(ptBegin.x - len, ptBegin.y);
            else
                return new Point(ptBegin.x + len, ptBegin.y);
        dx = Math.abs(dx);
        dy = Math.abs(dy);
        int decline = (int)Math.sqrt(Math.pow(dx, 2D) + Math.pow(dy, 2D));
        int _x = (len * dx) / decline;
        int _y = (len * dy) / decline;
        if(xIsLarge && yIsLarge)
            return new Point(ptBegin.x - _x, ptBegin.y - _y);
        if(xIsLarge)
            return new Point(ptBegin.x - _x, ptBegin.y + _y);
        if(yIsLarge)
            return new Point(ptBegin.x + _x, ptBegin.y - _y);
        else
            return new Point(ptBegin.x + _x, ptBegin.y + _y);
    }

    private void drawArrowLine(StringBuffer buf, Point ptBegin, Point ptEnd, double angle)
    {
        boolean xIsLarge = false;
        boolean yIsLarge = false;
        int dx = ptEnd.x - ptBegin.x;
        int dy = ptEnd.y - ptBegin.y;
        if(dx < 0)
            xIsLarge = true;
        if(dy < 0)
            yIsLarge = true;
        dx = Math.abs(dx);
        dy = Math.abs(dy);
        if(dx == 0 && dy == 0)
            return;
        angle = Math.toRadians(angle);
        Point ptLeft = new Point();
        Point ptRight = new Point();
        Point ptCurEnd = null;
        if(dx == 0)
        {
            double rdx = (double)hypotenuseSize * Math.sin(angle);
            double rdy = (double)hypotenuseSize * Math.cos(angle);
            if(yIsLarge)
            {
                ptLeft.x = ptEnd.x - (int)rdx;
                ptLeft.y = ptEnd.y + (int)rdy;
                ptRight.x = ptEnd.x + (int)rdx;
                ptRight.y = ptEnd.y + (int)rdy;
                ptCurEnd = new Point(ptEnd.x, ptEnd.y + (int)rdy);
            } else
            {
                ptLeft.x = ptEnd.x - (int)rdx;
                ptLeft.y = ptEnd.y - (int)rdy;
                ptRight.x = ptEnd.x + (int)rdx;
                ptRight.y = ptEnd.y - (int)rdy;
                ptCurEnd = new Point(ptEnd.x, ptEnd.y - (int)rdy);
            }
        } else
        if(dy == 0)
        {
            double rdx = (double)hypotenuseSize * Math.cos(angle);
            double rdy = (double)hypotenuseSize * Math.sin(angle);
            if(xIsLarge)
            {
                ptLeft.x = ptEnd.x + (int)rdx;
                ptLeft.y = ptEnd.y - (int)rdy;
                ptRight.x = ptEnd.x + (int)rdx;
                ptRight.y = ptEnd.y + (int)rdy;
                ptCurEnd = new Point(ptEnd.x + (int)rdx, ptEnd.y);
            } else
            {
                ptLeft.x = ptEnd.x - (int)rdx;
                ptLeft.y = ptEnd.y - (int)rdy;
                ptRight.x = ptEnd.x - (int)rdx;
                ptRight.y = ptEnd.y + (int)rdy;
                ptCurEnd = new Point(ptEnd.x - (int)rdx, ptEnd.y);
            }
        } else
        {
            double DY = ptEnd.y - ptBegin.y;
            double DX = ptEnd.x - ptBegin.x;
            double a1 = Math.atan(Math.abs(DY / DX));
            double b1 = Math.toRadians(90D) - a1 - angle;
            double b2 = Math.abs(angle - a1);
            double inclined1 = (double)hypotenuseSize / Math.cos(angle);
            if(xIsLarge && yIsLarge)
            {
                ptLeft.x = ptEnd.x + (int)(inclined1 * Math.sin(b1));
                ptLeft.y = ptEnd.y + (int)(inclined1 * Math.cos(b1));
                ptRight.x = ptEnd.x + (int)(inclined1 * Math.cos(b2));
                if(angle - a1 > 0.0D)
                    ptRight.y = ptEnd.y + (int)(inclined1 * Math.sin(b2));
                else
                    ptRight.y = ptEnd.y + (int)(inclined1 * Math.sin(b2));
                ptCurEnd = new Point(ptEnd.x + (int)((double)hypotenuseSize * Math.cos(a1)), ptEnd.y + (int)((double)hypotenuseSize * Math.sin(a1)));
            } else
            if(xIsLarge)
            {
                ptLeft.x = ptEnd.x + (int)(inclined1 * Math.sin(b1));
                ptLeft.y = ptEnd.y - (int)(inclined1 * Math.cos(b1));
                ptRight.x = ptEnd.x + (int)(inclined1 * Math.cos(b2));
                if(angle - a1 > 0.0D)
                    ptRight.y = ptEnd.y + (int)(inclined1 * Math.sin(b2));
                else
                    ptRight.y = ptEnd.y - (int)(inclined1 * Math.sin(b2));
                ptCurEnd = new Point(ptEnd.x + (int)((double)hypotenuseSize * Math.cos(a1)), ptEnd.y - (int)((double)hypotenuseSize * Math.sin(a1)));
            } else
            if(yIsLarge)
            {
                ptLeft.x = ptEnd.x - (int)(inclined1 * Math.sin(b1));
                ptLeft.y = ptEnd.y + (int)(inclined1 * Math.cos(b1));
                ptRight.x = ptEnd.x - (int)(inclined1 * Math.cos(b2));
                if(angle - a1 > 0.0D)
                    ptRight.y = ptEnd.y - (int)(inclined1 * Math.sin(b2));
                else
                    ptRight.y = ptEnd.y + (int)(inclined1 * Math.sin(b2));
                ptCurEnd = new Point(ptEnd.x - (int)((double)hypotenuseSize * Math.cos(a1)), ptEnd.y + (int)((double)hypotenuseSize * Math.sin(a1)));
            } else
            {
                ptLeft.x = ptEnd.x - (int)(inclined1 * Math.sin(b1));
                ptLeft.y = ptEnd.y - (int)(inclined1 * Math.cos(b1));
                ptRight.x = ptEnd.x - (int)(inclined1 * Math.cos(b2));
                if(angle - a1 > 0.0D)
                    ptRight.y = ptEnd.y + (int)(inclined1 * Math.sin(b2));
                else
                    ptRight.y = ptEnd.y - (int)(inclined1 * Math.sin(b2));
                ptCurEnd = new Point(ptEnd.x - (int)((double)hypotenuseSize * Math.cos(a1)), ptEnd.y - (int)((double)hypotenuseSize * Math.sin(a1)));
            }
        }
        drawLine(buf, ptBegin, ptCurEnd, 0, false);
        drawLine(buf, ptLeft, ptEnd, 0, true);
        drawLine(buf, ptRight, ptEnd, 0, true);
        drawLine(buf, ptLeft, ptRight, 0, true);
        fillArrow(buf, ptLeft, ptRight, ptEnd);
    }

    private void fillArrow(StringBuffer buf, Point a, Point b, Point c)
    {
        buf.append("var arrX =new Array()\r\n");
        buf.append("var arrY =new Array()\r\n");
        buf.append((new StringBuilder()).append("arrX[0]  =").append(m_zoomQuotiety * (double)a.x).append("\r\n").toString());
        buf.append((new StringBuilder()).append("arrX[1]  =").append(m_zoomQuotiety * (double)b.x).append("\r\n").toString());
        buf.append((new StringBuilder()).append("arrX[2]  =").append(m_zoomQuotiety * (double)c.x).append("\r\n").toString());
        buf.append((new StringBuilder()).append("arrY[0]  =").append(m_zoomQuotiety * (double)a.y).append("\r\n").toString());
        buf.append((new StringBuilder()).append("arrY[1]  =").append(m_zoomQuotiety * (double)b.y).append("\r\n").toString());
        buf.append((new StringBuilder()).append("arrY[2]  =").append(m_zoomQuotiety * (double)c.y).append("\r\n").toString());
        buf.append("fillPolygon(arrX,arrY)\r\n");
    }

    public void handleConnectors(StringBuffer bufLine, StringBuffer bufLineText, List connections)
    {
        if(connections == null)
            return;
        int length = connections.size();
        for(int i = 0; i < length; i++)
            handleConnector(bufLine, bufLineText, (ConnectionImpl)connections.get(i));

    }

    public String getStateImgUrl(State s)
    {
        if(s.getImgSrc() != null && s.getImgSrc().length() > 0)
        {
            return s.getImgSrc();
        } 
        else
        {
            String imgUrl = null;
            String imgName = (new StringBuilder()).append(s.getType()).append("_").append(s.getCurrentState()).append(".gif").toString();
          
            String path=imagePath.substring(this.contextPath.length()+1);
            String customizePath=(new StringBuilder().append(webAppPath).append(path).append("/").append(this.processDefName).append("/").append(s.getID()).append("_").append(s.getCurrentState()).append(".gif")).toString();
            File file=new File(customizePath);
            if(file.exists()){
            	imgUrl=(new StringBuilder().append(imagePath).append("/").append(this.processDefName).append("/").append(s.getID()).append("_").append(s.getCurrentState()).append(".gif")).toString();
            }else{
            	imgUrl = (new StringBuilder()).append(imagePath).append("/").append(imgName).toString();
            }
            return imgUrl;
        }
    }

    private Point getStateTextPosition(State s)
    {
        Point textPoint = new Point();
        textPoint.x = s.getX() + m_left + (imageSize - StringUtil.ifNullToBlank(s.getName()).length() * 2 * fontSize) / 2;
        textPoint.y = s.getY() + m_top + imageSize + 2;
        return textPoint;
    }

    public void setImagePath(String imagePath)
    {
        this.imagePath = imagePath;
    }


	/**
	 * ��ȡͼƬ��С
	 * @return
	 */
	public int getImageSize() {
		return imageSize;
	}

	/**
	 * ����ͼƬ��С
	 * @param imageSize
	 */
	public void setImageSize(int imageSize) {
		this.imageSize = imageSize;
	}


	/**
	 * ��ȡ���̶�����
	 * @return
	 */
	public String getProcessDefName() {
		return processDefName;
	}

	/**
	 * �������̶�����
	 * @param processDefName
	 */
	public void setProcessDefName(String processDefName) {
		this.processDefName = processDefName;
	}


	public void setWebAppPath(String webAppPath) {
		this.webAppPath = webAppPath;
	}
	
	
	


}
